package com.mriassl.consumer.user.web;
 
import java.util.concurrent.Callable;
 
/**
 * 试验 Java 的 Future 用法
 */
public class FutureTest {
 
    public static class Task implements Callable<String> {
    	
    	private int sortno;
		public Task(int sortno) {
			super();
			this.sortno = sortno;
		}
		@Override
        public String call() throws Exception {
            String tid = String.valueOf(Thread.currentThread().getId());
            System.out.printf("%d_Thread#%s : in call\n", sortno, tid);
            return tid+"_"+sortno;
        }
    }
 
//    public static void main(String[] args) throws InterruptedException, ExecutionException {
//        List<Future<String>> results = new ArrayList<Future<String>>();
//        ExecutorService es = Executors.newCachedThreadPool();
//        for(int i=0; i<100;i++){
//        	results.add(es.submit(new Task(i)));
//        }
//        es.shutdown();
//        for(Future<String> res : results){
//        	System.out.println(res.get());
//        }
//    }
 
}